package com.example.liwushuo;

import java.util.ArrayList;
import java.util.List;
import com.example.liwushuo.adapter.TallAdapter;
import com.example.liwushuo.bean.Item;
import com.example.liwushuo.fragment.GoodsInfoFragment;
import com.example.liwushuo.fragment.OneGoodsImageInfo;
import com.example.liwushuo.fragment.UserTallFragment;
import com.viewpagerindicator.TabPageIndicator;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.support.v7.app.ActionBarActivity;
import android.view.Window;

public class GoodsInfoActivity extends ActionBarActivity {

	// 这是下面评论的控件

	private TabPageIndicator tab;
	private ViewPager Tab_viewPager;

	private TallAdapter tAdapter;
	private List<Fragment> list;
	private Item item;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.activity_goods_info);

		item = (Item) getIntent().getSerializableExtra("item");
		GoodsInfoFragment infoFragment = new GoodsInfoFragment();
		Bundle args = new Bundle();
		args.putSerializable("item", item);
		infoFragment.setArguments(args);

		getSupportFragmentManager().beginTransaction()
				.replace(R.id.goodsInfo, infoFragment).commit();

		InitTallView();

	}

	private void InitTallView() {
		String[] titles = { "图片展示", "评论" };
		tab = (TabPageIndicator) findViewById(R.id.goods_tabPage);
		Tab_viewPager = (ViewPager) findViewById(R.id.goods_viewPager);
		list = new ArrayList<Fragment>();

		Bundle args = new Bundle();
		args.putLong("id", item.getData().getId());

		OneGoodsImageInfo info = new OneGoodsImageInfo();
		info.setArguments(args);
		UserTallFragment tallFragment = new UserTallFragment();
		tallFragment.setArguments(args);
		list.add(info);
		list.add(tallFragment);

		tAdapter = new TallAdapter(getSupportFragmentManager(), list, titles);
		Tab_viewPager.setAdapter(tAdapter);
		tab.setViewPager(Tab_viewPager);
	}
}
